#include "cpp_helper.hpp"

#include <cuda_runtime_api.h>

int get_cudart_version()
{
    return CUDART_VERSION;
}

std::string get_compiling_cuda_version()
{
    std::ostringstream oss;
    // copied from
    // https://github.com/pytorch/pytorch/blob/master/aten/src/ATen/cuda/detail/CUDAHooks.cpp#L231
    auto printCudaStyleVersion = [&](int v) {
        oss << (v / 1000) << "." << (v / 10 % 100);
        if (v % 10 != 0) {
        oss << "." << (v % 10);
        }
    };
    printCudaStyleVersion(get_cudart_version());
    return oss.str();
}

std::string get_compiler_version()
{
    std::ostringstream ss;
#if defined(__GNUC__)
#ifndef __clang__
    { ss << "GCC " << __GNUC__ << "." << __GNUC_MINOR__; }
#endif
#endif

#if defined(__clang_major__)
    {
        ss << "clang " << __clang_major__ << "." << __clang_minor__ << "."
        << __clang_patchlevel__;
    }
#endif

#if defined(_MSC_VER)
    { ss << "MSVC " << _MSC_FULL_VER; }
#endif
    return ss.str();
}
